﻿using NUnit.Framework;

namespace DictionaryExt.Test {

    [TestFixture]
    public class SplitInPairWith1Sep {

        [Test]
        public void With1Entry() {
            const string s = "a=1";
            string[] result = StringExt.StringExt.SplitInPair(s,StringExt.StringExt.RemoveSurroundingBlanks.No);
            Assert.AreEqual("a", result[0]);
            Assert.AreEqual("1", result[1]);
            Assert.AreEqual(2, result.Length);
        }

        [Test]
        public void MissingSep() {
            Assert.Throws<StringExt.PatternException>(MissingSepException);
        }
        static void MissingSepException() {
            const string s = "a1";
            string[] result = StringExt.StringExt.SplitInPair(s, StringExt.StringExt.RemoveSurroundingBlanks.No);
            Assert.AreEqual("a1", result[0]);
            Assert.AreEqual(1, result.Length);
        }

        [Test]
        public void Ending1Sep() {
            Assert.Throws<StringExt.PatternException>(Ending1SepException);
        }
        static void Ending1SepException() {
            const string s = "a=";
            string[] result = StringExt.StringExt.SplitInPair(s, StringExt.StringExt.RemoveSurroundingBlanks.No);
            Assert.AreEqual("a", result[0]);
            Assert.AreEqual(1, result.Length);
        }

        [Test]
        public void Ending2Sep() {
            Assert.Throws<StringExt.PatternException>(Ending2SepException);
        }
        static void Ending2SepException() {
            const string s = "a==";
            string[] result = StringExt.StringExt.SplitInPair(s, StringExt.StringExt.RemoveSurroundingBlanks.No);
            Assert.AreEqual("a", result[0]);
            Assert.AreEqual(1, result.Length);
        }

        [Test]
        public void Leading2Sep() {
            Assert.Throws<StringExt.PatternException>(Leading2SepException);
        }
        static void Leading2SepException() {
            const string s = "==a";
            string[] result = StringExt.StringExt.SplitInPair(s, StringExt.StringExt.RemoveSurroundingBlanks.No);
            Assert.AreEqual("a", result[0]);
            Assert.AreEqual(1, result.Length);
        }
    }
}
